<!DOCTYPE HTML>
<script src="../resources/js-test.js"></script>
<script>
description("Accessing Navigator Gamepad methods on a closed window.");

window.jsTestIsAsync = true;

var expectedLength = 0;
var w;
function processMessage(event) {
    if (event.data == "opened") {
        w.close();
    } else if (event.data == "closed") {
        shouldBeEqualToNumber("w.navigator.getGamepads().length", expectedLength);
        finishJSTest();
    }
}

if (window.gamepadController) {
    if (window.testRunner) {
        testRunner.dumpAsText();
        testRunner.setPopupBlockingEnabled(false);
        testRunner.waitUntilDone();
    }
    w = window.open('../resources/window-postmessage-open-close.html');
    expectedLength = w.navigator.getGamepads().length;
    window.addEventListener("message", processMessage, false);
} else {
    console.log("FAIL: no gamepad controller available.")
}
</script>
